<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录 - 连连看游戏系统</title>
    <link rel="stylesheet" th:href="@{/static/css/common.css}">
    <style>
        .login-container {
            max-width: 450px;
            margin: 0 auto;
        }
        
        .game-icons {
            display: flex;
            justify-content: center;
            gap: 15px;
            margin-bottom: 30px;
        }
        
        .game-icon {
            width: 50px;
            height: 50px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 24px;
            color: #fff;
            animation: float 3s ease-in-out infinite;
        }
        
        .game-icon:nth-child(2) {
            animation-delay: 0.5s;
        }
        
        .game-icon:nth-child(3) {
            animation-delay: 1s;
        }
        
        @keyframes float {
            0%, 100% { transform: translateY(0); }
            50% { transform: translateY(-10px); }
        }
        
        .login-options {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }
        
        .remember-me {
            display: flex;
            align-items: center;
            gap: 5px;
        }
    </style>
</head>
<body>
    <div class="page-header">
        <h1>🎮 连连看游戏系统</h1>
        <p class="subtitle">欢迎回来，开始你的游戏之旅</p>
    </div>

    <div class="container">
        <div class="login-container">
            <div class="card">
                <div class="game-icons">
                    <div class="game-icon">🎯</div>
                    <div class="game-icon">🎨</div>
                    <div class="game-icon">✨</div>
                </div>
                
                <h2 class="card-title">用户登录</h2>
                
                <div id="alertMessage" class="alert"></div>
                
                <form id="loginForm">
                    <div class="form-group">
                        <label for="account">账号/手机号 <span class="required">*</span></label>
                        <input type="text" 
                               id="account" 
                               name="account" 
                               class="form-control" 
                               placeholder="请输入账号或手机号"
                               required>
                    </div>
                    
                    <div class="form-group">
                        <label for="password">密码 <span class="required">*</span></label>
                        <input type="password" 
                               id="password" 
                               name="password" 
                               class="form-control" 
                               placeholder="请输入密码"
                               required>
                    </div>
                    
                    <div class="login-options">
                        <div class="remember-me">
                            <input type="checkbox" id="remember" name="remember">
                            <label for="remember" style="margin: 0;">记住我</label>
                        </div>
                        <a href="#" class="text-link">忘记密码?</a>
                    </div>
                    
                    <button type="submit" class="btn btn-primary btn-block" id="loginBtn">
                        登录
                    </button>
                </form>
                
                <div class="divider">
                    <span>还没有账号?</span>
                </div>
                
                <div class="text-center">
                    <a th:href="@{/user/register}" class="btn btn-secondary btn-block">
                        立即注册
                    </a>
                </div>
                
                <div class="text-center" style="margin-top: 20px;">
                    <a th:href="@{/admin/login}" class="text-link">管理员登录</a>
                </div>
            </div>
        </div>
    </div>

    <footer class="page-footer">
        <p>&copy; 2024 连连看游戏系统. All rights reserved.</p>
        <p>让游戏更有趣，让生活更精彩</p>
    </footer>

    <script>
        // 登录表单提交
        document.getElementById('loginForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const account = document.getElementById('account').value.trim();
            const password = document.getElementById('password').value;
            
            if (!account || !password) {
                showAlert('请填写完整的登录信息', 'error');
                return;
            }
            
            const loginBtn = document.getElementById('loginBtn');
            loginBtn.disabled = true;
            loginBtn.innerHTML = '<span class="loading"></span> 登录中...';
            
            // 发送登录请求
            fetch('/user/login', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({
                    account: account,
                    password: password
                })
            })
            .then(response => response.json())
            .then(data => {
                if (data.code === 200) {
                    showAlert('登录成功！正在跳转...', 'success');
                    setTimeout(() => {
                        window.location.href = '/user/home';
                    }, 1000);
                } else {
                    showAlert(data.message || '登录失败', 'error');
                    loginBtn.disabled = false;
                    loginBtn.innerHTML = '登录';
                }
            })
            .catch(error => {
                console.error('Error:', error);
                showAlert('网络错误，请稍后重试', 'error');
                loginBtn.disabled = false;
                loginBtn.innerHTML = '登录';
            });
        });
        
        // 显示提示信息
        function showAlert(message, type) {
            const alertDiv = document.getElementById('alertMessage');
            alertDiv.className = `alert alert-${type} show`;
            alertDiv.textContent = message;
            
            setTimeout(() => {
                alertDiv.className = 'alert';
            }, 5000);
        }
    </script>
</body>
</html>

